home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr15
/
rtag10.zip
/
BOUNC.RTA
< prev
next >
Wrap
Text File
|
1993-05-24
|
2KB
|
75 lines
// Animation to simulate a bouncing ball.
// File declarations
bfile bounc // bounc.bat will be the batch driver file
// Simulation parameters
var numframes = 70 // Number of frames to generate
var endtime = 26.2 // Time at end of simulation
var timestep = .05 // Time for each simulation step
var xstart = -9.2 // Initial X position of ball.
var g = .6 // Gravitational acceleration
var drag = .32 // Frictional drag on slide
var angle = 30 // Downward angle of the slide
// Variable declarations
var x // Current x position
var y // Current y position
var xv // X velocity
var yv // Y velocity
var time // Current simulated time
var frametime // Generate frame after this much time passes
var nextframetime // Time when next frame should be displayed
// ----- Executable code -----
// First time inititlization
// Initial position
x = xstart
frametime = endtime / numframes
// Begin main simulation loop
for time=0 while time<endtime step timestep do
// See if ball is still on the slide
if (x <= -5.75) then
// Ball is still on the slide
y = 7.43 - (5.75 + x) * tan(angle)
// Compute next x position
xv = xv + timestep * g * sin(angle) * drag
x = x + timestep * xv
// Compute y velocity
yv = -xv * sin(angle)
else
// Ball is in free fall
// Apply acceleration to get new speed
yv = yv - timestep * g
// Compute new ball position
y = y + timestep * yv
// If ball hit floor, reverse direction & loose energy
if (y <= 0) then
print "Hit floor. time=`time`, x=`x`, y=`y`"
y = 0
yv = -.75 * yv
endif
// Compute x position. Note: x velocity is not changing.
x = x + timestep * xv
// Don't let ball go past right side of can
if (x > 8.2) then
x = 8.2
endif
endif
// See if it is time to start a new frame
if (time >= nextframetime) then
// Start a new frame
nextframe
// Print current ball position
print "At frame `curframe`, time=`time`, X=`x`, and Y=`y`"
// Generate commands to create the include file.
bwrite "echo #declare xpos = `x` > bounc.inc"
bwrite "echo #declare ypos = `y` >> bounc.inc"
// Generate command to run POV-Ray to render the frame.
bwrite "call render bounc bounc`###`"
// Remember when next frame should be produced
nextframetime = curframe * frametime
endif
// End of main simulation loop
endfor
// Write batch command for end of run processing
epilog
bwrite "dodta BOUNC /S7"